package lanou.giftsay_01.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import lanou.giftsay_01.R;
import lanou.giftsay_01.bean.NormalBean;
import lanou.giftsay_01.fragment.categorybody.NormalItemOnClickListener;

/**
 * Created by dllo on 16/8/18.
 */
public class NormalRvAdapter extends RecyclerView.Adapter<NormalRvAdapter.MyViewHolder> {
    private Context context ;
    private NormalBean normalBean ;
    int tag ;
     NormalItemOnClickListener normalItemOnClickListener;
    public NormalRvAdapter(Context context ,int tag) {
        this.context = context;
        this.tag =tag;
    }

    public void setNormalItemOnClickListener(NormalItemOnClickListener normalItemOnClickListener) {
        this.normalItemOnClickListener = normalItemOnClickListener;
    }

    public void setNormalBean(NormalBean normalBean) {
        this.normalBean = normalBean;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_normal , parent , false);
        MyViewHolder myViewHolder =new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                normalItemOnClickListener.onClick(position , normalBean , tag);
            }
        });

        switch (tag) {
            case 0:
                Picasso.with(context).load(normalBean.getData().getChannel_groups().get(0).getChannels().get(position).getCover_image_url()).into(holder.iv);
                break;

            case 1:
                Picasso.with(context).load(normalBean.getData().getChannel_groups().get(1).getChannels().get(position).getCover_image_url()).into(holder.iv);
                break;

            case 2:
                Picasso.with(context).load(normalBean.getData().getChannel_groups().get(2).getChannels().get(position).getCover_image_url()).into(holder.iv);
                break;
        }
    }
    @Override
    public int getItemCount() {
        return 6;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView iv ;
        public MyViewHolder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.normal_iv);
        }
    }
}
